package org.ndx.majick.properties;

import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

/**
 * Extension of {@link Property} to provide vetoable changes when trying to set properties
 * @author Nicolas Delsaux
 */
public interface VetoableProperty<Type extends Object> extends Property<Type> {
    /**
     * Contrary to parent interface, usage of this method is discouraged when trying to set value.
     * Indeed, in this updated interface, set is supposed to rely upon {@link #setVeto(java.lang.Object) 
     * @deprecated should be avoided in favor of {@link #setVeto(java.lang.Object)}
     * @param newValue
     */
    public void set(Type newValue);
    
    /**
     * Default setter for vetoable properties.
     * When changing value with this kind of setter, contract of {@link VetoablePropertyChange}
     * is to be fully respected : value must be set and, if any of the veto listeners refuse, an 
     * event resetting value to its previous one should be sent, and finally, initial exception is fired.
     * @param newValue value we expect to set
     * @throws java.beans.PropertyVetoException if any of the veto listeners refuse this modification.
     */
    public void setVeto(Type newValue) throws PropertyVetoException;
    /**
     * Adds a vetoable change listener to the list of registered ones
     * @param listener listener to add
     */
    public void addVetoableChangeListener(VetoableChangeListener listener);
    public void removeVetoableChangeListener(VetoableChangeListener listener);
}
